<!DOCTYPE html>
<html lang="">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="刘海屏适配。<meta-data android:name="android.max_aspect"  android:value="ratio_float"/>"/>




  <meta name="keywords" content="整理, ZOE码坊" />










  <link rel="alternate" href="/blog/default" title="ZOE码坊">




  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=2.9.0" />



<link rel="canonical" href="https://luys.gitee.io/blog/2018/09/02/Android工作学习收集整理（七月）/"/>



  <link rel="stylesheet" type="text/css" href="/blog/lib/fancybox/jquery.fancybox.css" />




  <link rel="stylesheet" type="text/css" href="/blog/lib/nprogress/nprogress.min.css" />



<link rel="stylesheet" type="text/css" href="/blog/css/style.css?v=2.9.0" />



  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>





  <script src="//cdn1.lncld.net/static/js/3.1.1/av-min.js"></script>
  <script id="leancloud">
    AV.init({
      appId: "kdb8x3rBNollDwJ8ulzKQPb3-gzGzoHsz",
      appKey: "dRlqoI7xVfUXI5urx5r6uOYC"
    });
  </script>




<script>
  window.config = {"title":"ZOE码坊","subtitle":null,"description":null,"author":"Sam Lu","language":null,"timezone":null,"url":"https://luys.gitee.io/blog","root":"/blog/","permalink":":year/:month/:day/:title/","permalink_defaults":null,"source_dir":"source","public_dir":"public/blog","tag_dir":"tags","archive_dir":"archives","category_dir":"categories","code_dir":"downloads/code","i18n_dir":":lang","skip_render":null,"new_post_name":":title.md","default_layout":"post","titlecase":false,"external_link":true,"filename_case":0,"render_drafts":false,"post_asset_folder":false,"relative_link":false,"future":true,"highlight":{"enable":true,"auto_detect":false,"line_number":true,"tab_replace":null},"default_category":"uncategorized","category_map":null,"tag_map":null,"date_format":"YYYY-MM-DD","time_format":"HH:mm:ss","per_page":10,"pagination_dir":"page","theme":"even","deploy":{"type":"git","repo":"https://gitee.com/luys/blog.git","branch":"master"},"ignore":[],"keywords":null,"index_generator":{"per_page":10,"order_by":"-date","path":""},"category_generator":{"per_page":10},"tag_generator":{"per_page":10},"archive_generator":{"per_page":10,"yearly":true,"monthly":true,"daily":false},"marked":{"gfm":true,"pedantic":false,"sanitize":false,"tables":true,"breaks":true,"smartLists":true,"smartypants":true,"modifyAnchors":"","autolink":true},"server":{"port":4000,"log":false,"compress":false,"header":true},"since":2015,"favicon":"/favicon.ico","rss":"default","menu":{"Home":"/","Tags":"/tags","Categories":"/categories"},"color":"Cobalt Blue","toc":true,"fancybox":true,"pjax":true,"copyright":{"enable":true,"license":"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\" target=\"_blank\">知识共享署名-非商业性使用 4.0 国际许可协议</a>"},"reward":{"enable":false,"qrCode":{"wechat":null,"alipay":null}},"social":{"email":"ltym_lys@126.com","stack-overflow":null,"twitter":null,"facebook":null,"linkedin":null,"google":null,"github":"https://github.com/ltym2016","weibo":null,"zhihu":null,"douban":null,"pocket":null,"tumblr":null,"instagram":null},"leancloud":{"app_id":"kdb8x3rBNollDwJ8ulzKQPb3-gzGzoHsz","app_key":"dRlqoI7xVfUXI5urx5r6uOYC"},"baidu_analytics":null,"baidu_verification":null,"google_analytics":null,"google_verification":null,"disqus_shortname":null,"changyan":{"appid":null,"appkey":null},"livere_datauid":null,"version":"2.9.0"};
</script>

    <title> Android工作学习收集整理（七月） - ZOE码坊 </title>
  </head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/blog/." class="logo">ZOE码坊</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/blog/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/blog/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/blog/categories">
        <li class="mobile-menu-item">
          
          
            分类
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/blog/." class="logo">ZOE码坊</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/categories">
            
            
              分类
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          Android工作学习收集整理（七月）
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2018-09-02
        </span>
        
          <div class="post-category">
            
              <a href="/blog/categories/月度整理/">月度整理</a>
            
          </div>
        
        
        <div class="post-visits"
             data-url="/blog/2018/09/02/Android工作学习收集整理（七月）/"
             data-title="Android工作学习收集整理（七月）">
            阅读次数 0
          </div>
        
      </div>
    </header>

    
    
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#刘海屏适配-参考"><span class="toc-text">刘海屏适配 参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#小米8和8SE上获取屏幕高度问题"><span class="toc-text">小米8和8SE上获取屏幕高度问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#启动页logo被虚拟按键挡住的问题"><span class="toc-text">启动页logo被虚拟按键挡住的问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#启动页在小米手机中刘海屏没有适配的问题"><span class="toc-text">启动页在小米手机中刘海屏没有适配的问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#项目中分割线消失的问题"><span class="toc-text">项目中分割线消失的问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Only-fullscreen-opaque-activities-can-request-orientation"><span class="toc-text">Only fullscreen opaque activities can request orientation</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Glide-4-0使用"><span class="toc-text">Glide 4.0使用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#混淆为什么要保留类名和方法名？"><span class="toc-text">混淆为什么要保留类名和方法名？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ProGuard-去除log日记"><span class="toc-text">ProGuard 去除log日记</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#proguard-android-optimize-txt和proguard-android-txt到底有什么区别？"><span class="toc-text">proguard-android-optimize.txt和proguard-android.txt到底有什么区别？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#mac上Apktool下载和使用-Apktool源码"><span class="toc-text">mac上Apktool下载和使用  Apktool源码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Android-消息机制"><span class="toc-text">Android 消息机制</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Json解析key为关键字问题-详解"><span class="toc-text">Json解析key为关键字问题 详解</span></a></li></ol>
    </div>
  </div>



    <div class="post-content">
      
        <h3 id="刘海屏适配-参考"><a href="#刘海屏适配-参考" class="headerlink" title="刘海屏适配 参考"></a>刘海屏适配 <a href="https://blog.csdn.net/weelyy/article/details/79284332#%E5%9C%A8androidmanifestxml%E5%A3%B0%E6%98%8Emaxaspect%E5%80%BC" target="_blank" rel="noopener">参考</a></h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">meta-data</span> <span class="attr">android:name</span>=<span class="string">"android.max_aspect"</span>  </span></span><br><span class="line"><span class="tag">           <span class="attr">android:value</span>=<span class="string">"ratio_float"</span>/&gt;</span></span><br></pre></td></tr></table></figure>
<ul>
<li>android.max_aspect:Android官方提供了适配方案，即提高App所支持的最大屏幕纵横比</li>
<li>其中ratio_float为浮点数，官方建议为2.1或更大，因为18.5：9=2.055555555……，如果日后出现纵横比更大的手机，此值将需要设为更大。</li>
<li>在AndroidManifest中针对Activity标签添加android:resizeableActivity = “true”，也可以实现全屏显示，但此设置只针对Activity生效，且增加了此属性该activity也会支持分屏显示</li>
</ul>
<h3 id="小米8和8SE上获取屏幕高度问题"><a href="#小米8和8SE上获取屏幕高度问题" class="headerlink" title="小米8和8SE上获取屏幕高度问题"></a>小米8和8SE上获取屏幕高度问题</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">// 方法一</span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">getHeight</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">       WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);</span><br><span class="line">       Display display = windowManager.getDefaultDisplay();</span><br><span class="line">       DisplayMetrics dm = <span class="keyword">new</span> DisplayMetrics();</span><br><span class="line">       display.getMetrics(dm);</span><br><span class="line">       <span class="keyword">int</span> height = dm.heightPixels;</span><br><span class="line">       <span class="keyword">return</span> height;</span><br><span class="line">   &#125;</span><br><span class="line"><span class="comment">// 方法二</span></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">getRealHeight</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">       WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);</span><br><span class="line">       Display display = windowManager.getDefaultDisplay();</span><br><span class="line">       DisplayMetrics dm = <span class="keyword">new</span> DisplayMetrics();</span><br><span class="line">       <span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN_MR1) &#123;</span><br><span class="line">           display.getRealMetrics(dm);</span><br><span class="line">       &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">           display.getMetrics(dm);</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">int</span> realHeight = dm.heightPixels;</span><br><span class="line">       <span class="keyword">return</span> realHeight;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>正常获取手机屏幕方法有以上两种方式，用的比较多的是方法一</li>
<li>在全面屏中，利用方法一获取屏幕高度是不包含下面的虚拟按键的高度的。不管是在设置里面切换虚拟按键隐藏还是显示。</li>
<li>用原生的方法去判断小米全面屏手机是否带有虚拟按键也是不行的，不管虚拟按键是隐藏或是显示，都是返回true（有虚拟按键）</li>
<li>对于如何监听小米手机虚拟按键的显示还是隐藏，可以通过下面的方法做判断。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 判断小米全面屏手机的虚拟按键是否显示，也就是判断是否为全面屏</span></span><br><span class="line"><span class="keyword">boolean</span> isFull = Settings.Global.getInt(context.getContentResolver(), <span class="string">"force_fsg_nav_bar"</span>, <span class="number">0</span>) != <span class="number">0</span>;</span><br></pre></td></tr></table></figure>
<h3 id="启动页logo被虚拟按键挡住的问题"><a href="#启动页logo被虚拟按键挡住的问题" class="headerlink" title="启动页logo被虚拟按键挡住的问题"></a>启动页logo被虚拟按键挡住的问题</h3><ul>
<li>原本在主题里设置的是android：windowbackground = “…”，换成android:background = “…”就可以了</li>
</ul>
<h3 id="启动页在小米手机中刘海屏没有适配的问题"><a href="#启动页在小米手机中刘海屏没有适配的问题" class="headerlink" title="启动页在小米手机中刘海屏没有适配的问题"></a>启动页在小米手机中刘海屏没有适配的问题</h3><ul>
<li>如果开发者认为应用的所有页面统一处理就行，可以使用该接口。在 Application 下增加一个 meta-data，用以声明该应用是否使用耳朵区。示例如下：</li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">meta-data</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:name</span>=<span class="string">"notch.config"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:value</span>=<span class="string">"portrait|landscape"</span>/&gt;</span></span><br></pre></td></tr></table></figure>
<ul>
<li>value 的取值可以是以下4种：</li>
<li>“none” 横竖屏都不绘制耳朵区</li>
<li>“portrait” 竖屏绘制到耳朵区</li>
<li>“landscape” 横屏绘制到耳朵区</li>
<li>“portrait|landscape” 横竖屏都绘制到耳朵区</li>
</ul>
<h3 id="项目中分割线消失的问题"><a href="#项目中分割线消失的问题" class="headerlink" title="项目中分割线消失的问题"></a>项目中分割线消失的问题</h3><ul>
<li>在项目中发现，进入一个页面后，返回看其他页面的时候，列表页的分割线就不见了，注意用的是同一个资源的颜色。</li>
<li>后来发现android中从同一个资源文件中加载出来的drawable会有共享状态，如果你加载出来多个drawable，当改变了其中一个的状态时，其他drawable的状态也会相应改变。</li>
<li>之前同事在一个页面里隐藏一个分割线的时候设置色值透明度为0，这样就导致了其他用到这个色值的都变成0。</li>
<li>解决办法：把这个drawable变为mutate drawable后，这个drawable就不会与其他drawable共享状态，注意mutate是不可逆的</li>
</ul>
<h3 id="Only-fullscreen-opaque-activities-can-request-orientation"><a href="#Only-fullscreen-opaque-activities-can-request-orientation" class="headerlink" title="Only fullscreen opaque activities can request orientation"></a>Only fullscreen opaque activities can request orientation</h3><ul>
<li>只有不透明的全屏activity可以自主设置界面方向</li>
<li>只有Android 8.0才会又这个问题，8.1貌似修复了</li>
<li>中转Activity不需要锁定屏幕</li>
<li>在activity节点中将设置方向的去掉</li>
</ul>
<h3 id="Glide-4-0使用"><a href="#Glide-4-0使用" class="headerlink" title="Glide 4.0使用"></a><a href="https://blog.csdn.net/u013005791/article/details/74532091" target="_blank" rel="noopener">Glide 4.0使用</a></h3><ul>
<li>开始使用中发现Glide.with(_mActivity).load(url)后面没有fitCenter和placeholder这样的方法。后来发现API多了个GlideApp，哪来的呢？</li>
<li>新建一个类继承AppGlideModule</li>
<li>类上添加注解@GlideModule，类里面不需要添加任何内容</li>
<li>clean project -&gt; rebuild project</li>
<li>build文件下会生成了四个类</li>
<li>这样就有GlideApp类了，用GlideApp代替Glide</li>
<li>支持gift</li>
<li>支持圆角，原生的Glide就提供了方法</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">GlideApp.with(_mActivity).load(headInfo.getImage())</span><br><span class="line">    <span class="comment">// 实现圆形图片</span></span><br><span class="line">    .apply(RequestOptions.bitmapTransform(<span class="keyword">new</span> CircleCrop()))</span><br><span class="line">    .placeholder(R.mipmap.icon_default_header)</span><br><span class="line">    .error(R.mipmap.icon_default_header)</span><br><span class="line">    .into(sdv_image);</span><br></pre></td></tr></table></figure>
<h3 id="混淆为什么要保留类名和方法名？"><a href="#混淆为什么要保留类名和方法名？" class="headerlink" title="混淆为什么要保留类名和方法名？"></a>混淆为什么要保留类名和方法名？</h3><ul>
<li>让C/C++程序可以通过jni使用对应的java方法</li>
<li>四大组件在AndroidManifest中已经注册了，需要保留，不然解析的时候会失败</li>
<li>R文件如果混淆的话，会导致引用错误</li>
</ul>
<h3 id="ProGuard-去除log日记"><a href="#ProGuard-去除log日记" class="headerlink" title="ProGuard 去除log日记"></a>ProGuard 去除log日记</h3><ul>
<li>一定要打开优化开关，也就是build.gradle中默认使用proguard-android-optimize.txt文件，这个文件已经默认打开了优化开关</li>
</ul>
<h3 id="proguard-android-optimize-txt和proguard-android-txt到底有什么区别？"><a href="#proguard-android-optimize-txt和proguard-android-txt到底有什么区别？" class="headerlink" title="proguard-android-optimize.txt和proguard-android.txt到底有什么区别？"></a>proguard-android-optimize.txt和proguard-android.txt到底有什么区别？</h3><ul>
<li>前者优化开启，后者优化关闭</li>
<li>都是在sdk下的</li>
<li>后者里面有个 -dontoptimize 表示关闭优化，去掉的话就是开启优化</li>
<li>优化会存在风险，不能保证在所有版本的Dalvik上都正常运行。</li>
</ul>
<h3 id="mac上Apktool下载和使用-Apktool源码"><a href="#mac上Apktool下载和使用-Apktool源码" class="headerlink" title="mac上Apktool下载和使用  Apktool源码"></a>mac上Apktool下载和使用  <a href="https://github.com/iBotPeaches/Apktool" target="_blank" rel="noopener">Apktool源码</a></h3><ul>
<li><a href="https://ibotpeaches.github.io/Apktool/install/" target="_blank" rel="noopener">mac 上下载</a></li>
<li>1.将 wrapper script 脚本文件保存为 “apktool.sh”</li>
<li>2.下载apktool-X最新版 重新命名为apktool.jar</li>
<li>3.将这两个文件夹已到 /usr/local/bin 目录下</li>
<li>4.增加这两个文件可执行权限</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">samMacBook-Pro:~ sam$ cd /usr/local/bin</span><br><span class="line">samMacBook-Pro:bin sam$ chmod a+x apktool.sh</span><br><span class="line">samMacBook-Pro:bin sam$ chmod a+x apktool.jar</span><br></pre></td></tr></table></figure>
<ul>
<li>切换到apk所在的文件夹，执行apktool.sh d file.apk</li>
<li>Apk 重新打包是指，首先用反编译工具得到smali代码（比如apktool），然后再由smali代码重新打包形成apk，最后重新签名才能运行在手机上。</li>
<li>如果apk被重新打包的话，如果想运行在真机上，是要重新签名的，这个时候我们可以判断签名和我们这的签名是否一致，不一致可以退出或杀死进程。 </li>
<li>通过packageManager 可以获取签名信息</li>
</ul>
<h3 id="Android-消息机制"><a href="#Android-消息机制" class="headerlink" title="Android 消息机制"></a><a href="https://v.youku.com/v_show/id_XNzIxNjM3Nzc2.html?spm=a2h0k.11417342.soresults.dtitle" target="_blank" rel="noopener">Android 消息机制</a></h3><ul>
<li>主线程在创建完成后，Android会默认创建一个looper循环</li>
<li>这个循环不停的读取消息队列（message queue 也是在主线程创建完成后生成的类）中的内容。</li>
<li>当一次循环读取到一个消息时就去进行一段处理代码，处理完成后，就将这条消息移除出消息队列。再在下一次循环中读取另一条消息。</li>
<li>比如，在屏幕上触摸一个button事件，会把这个消息放到消息队列的尾部，等待循环处理。这个是系统帮我们插入的。</li>
<li>如果要自己向主线程中插入消息的话，怎么办呢？当然是用Handler。sendMessage</li>
<li>至于looper读取到消息进行处理也是交给Handler去处理，一般系统插入的消息处理是交给dispatchMessage，而我们自己发送的消息是交给handleMessage处理，当然，没有明确规定，两者可以通用。</li>
<li>哪一个Handler发送消息就那个Handler处理消息，messageQueue是根据message的target去判断哪一个Handler发送消息的</li>
<li>Handler必要在有Looper的实例的情况下才能实例化</li>
</ul>
<h3 id="Json解析key为关键字问题-详解"><a href="#Json解析key为关键字问题-详解" class="headerlink" title="Json解析key为关键字问题 详解"></a>Json解析key为关键字问题 <a href="https://blog.csdn.net/qq_15975081/article/details/53391640?locationNum=11&amp;fps=1" target="_blank" rel="noopener">详解</a></h3><ul>
<li>编译工具是不允许你命名的变量名称为一些关键字的</li>
<li>可以通过注解的方式关联解析对象的key来解决这个问题</li>
<li>fastjson使用者</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@JSONField</span>(name=<span class="string">"package"</span>)</span><br><span class="line"><span class="keyword">private</span> PaiRedPackageEntity redpackage;</span><br></pre></td></tr></table></figure>
<ul>
<li>Gson 使用者</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@SerializedName</span>(<span class="string">"abstract"</span>)</span><br><span class="line"><span class="keyword">public</span> String myabstract;</span><br></pre></td></tr></table></figure>
<ul>
<li>Json数据出现动态key问题, fastjson和org.json可以解析，存放在map里</li>
</ul>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="https://luys.gitee.io/blog">Sam Lu</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="https://luys.gitee.io/blog/2018/09/02/Android工作学习收集整理（七月）/">https://luys.gitee.io/blog/2018/09/02/Android工作学习收集整理（七月）/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/blog/tags/整理/">整理</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
      <a class="prev" href="/blog/2018/09/02/Android工作学习收集整理（八月）/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">Android工作学习收集整理（八月）</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
    
    
      <a class="next" href="/blog/2018/09/02/Android工作学习收集整理（六月）/">
        <span class="next-text nav-default">Android工作学习收集整理（六月）</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:ltym_lys@126.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://github.com/ltym2016" class="iconfont icon-github" title="github"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
      
      <a href="/blog/atom.xml" class="iconfont icon-rss" title="rss"></a>
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
     
      2015 - 
    
    2018

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">Sam Lu</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  



  
  





  
    <script type="text/javascript" src="/blog/lib/jquery/jquery.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/fancybox/jquery.fancybox.pack.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/pjax/jquery.pjax.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/nprogress/nprogress.min.js"></script>
  


    <script type="text/javascript" src="/blog/js/src/even.js?v=2.9.0"></script>

  </body>
</html>
